var activity = require('./api/activity');
var user = require('./api/user');
var wechat = require('./api/wechatApi');
var image = require('./api/image');
var faction = require('./api/faction');
var wxpay = require('./api/wxpay');
var goods = require('./api/goods');
var OAuth2 = require('./service/OAuth2');
var auth = require('./service/auth');
var test = require('./api/test');

module.exports =  function (app){

    app.get('/totest', test.toTest);
    //app.post('/test_token', auth.csrf, test.testToken);

    app.get('/index', OAuth2.checkAuth, function(req, res, next){
        res.render('index', {});
    });
    app.get('/setCookie', wechat.setCookie);
    app.get('/deletCoockie', wechat.deletCoockie);
    app.get('/getAccessToken', wechat.getAccesstoken);
    app.post('/jsapiSign', wechat.jsapiSign);
    app.get('/img/:userId', image.getImg);
    app.get('/error', wechat.toError);
    app.get('/wechat', wechat.wechatGet);
    app.post('/wechat', wechat.wechatPost);
    // 授权回调
    app.get('/oauth2cb', OAuth2.oauth2cb);
    /**************************/
    app.get('/create', OAuth2.checkAuth, auth.csrf, activity.create);
    app.get('/create/:faction', OAuth2.checkAuth, auth.csrf, activity.createFactionAct);
    app.post('/saveAct', OAuth2.checkAuth, auth.csrf, activity.save);
    app.get('/invite/:id/:from?', OAuth2.checkAuth, activity.invite);
    app.get('/fetchAttends/:actId', OAuth2.checkAuth, activity.fetchAttends);
    app.get('/getJoinCode/:code', OAuth2.checkAuth, activity.getJoinCode);
    app.get('/actEdit/:id', OAuth2.checkAuth, activity.editAct);
    app.post('/finishMyInfo', OAuth2.checkAuth, user.completeInfo);
    app.post('/apply', OAuth2.checkAuth, activity.apply);
    app.post('/cancel', OAuth2.checkAuth, activity.cancel);
    app.get('/actlist/:pageNo?/:ajax?', OAuth2.checkAuth, activity.showActlist);
    app.post('/fetchActs', OAuth2.checkAuth, activity.fetchActs);
    app.get('/saveUser', user.saveUser);
    app.get('/user/:id?', OAuth2.checkAuth, user.getUser);
    app.get('/user/:id/:factionId', OAuth2.checkAuth, user.getUser);
    app.get('/editUser/:id/:forwardUrl?', OAuth2.checkAuth, user.editUser);
    app.post('/addTag', OAuth2.checkAuth, user.addTag);
    app.post('/removeTag', OAuth2.checkAuth, user.removeTag);
    app.get('/newCard/:cardId?', OAuth2.checkAuth, user.newCard);
    app.post('/receiveCard', OAuth2.checkAuth, user.receiveCard);
    app.post('/saveCard', OAuth2.checkAuth, user.saveCard);
    app.get('/myCircle', OAuth2.checkAuth, user.myCircle);
    app.post('/fetchUsers', OAuth2.checkAuth, user.fetchUsers);
    app.get('/refresh', OAuth2.checkAuth, image.refreshHeadimg);
    app.get('/myfactions', OAuth2.checkAuth, faction.myFactions);
    app.get('/newfaction', OAuth2.checkAuth, auth.csrf, faction.newFaction);
    app.get('/updatefaction/:id', OAuth2.checkAuth, auth.csrf, faction.updateFaction);
    app.post('/saveFaction', OAuth2.checkAuth, auth.csrf, faction.save);
    app.post('/faction_del', OAuth2.checkAuth, faction.delete);
    app.get('/faction/:id?', OAuth2.checkAuth, faction.verifyAccess, faction.faction);
    app.get('/faction/acts/:factionId/:pageNo', OAuth2.checkAuth, faction.fetchFactionActs);
    app.get('/faction/members/:id/:pageNo?', OAuth2.checkAuth, faction.members);
    app.get('/faction/info/:id/:from?', OAuth2.checkAuth, faction.information);
    app.post('/faction/join', OAuth2.checkAuth, faction.joinFaction);
    app.get('/faction/privacy/:factionId', OAuth2.checkAuth, faction.privacy);
    app.post('/faction/tick', OAuth2.checkAuth, faction.tick);
    app.get('/faction/log/:id', OAuth2.checkAuth, faction.factionLog);
    app.get('/faction/logs/:id/:pageNo?', OAuth2.checkAuth, faction.fetchFactionLogs);
    //
    app.get('/getRelsInfo/:id', OAuth2.checkAuth, user.getRelationInfos);
    //
    app.get('/setPrivacy', OAuth2.checkAuth, user.setPrivacy);
    app.post('/savePrivacy', OAuth2.checkAuth, user.savePrivacy);
    //
    app.get('/actScoreList/:actId/:score?/:no?', OAuth2.checkAuth, activity.actScoreList);
    app.post('/pickUpGift', OAuth2.checkAuth, activity.pickUpGift);

    app.post('/sentSuggest', OAuth2.checkAuth, wechat.sentSuggest);
    /****商品****/
    app.get('/goodslist/:factionId', OAuth2.checkAuth, goods.goodslist);
    app.get('/addGoods/:factionId', OAuth2.checkAuth, auth.csrf, goods.addGoods);
    app.post('/saveGoods', OAuth2.checkAuth, auth.csrf, goods.saveGoods);
    app.get('/updateGoods/:id', OAuth2.checkAuth, auth.csrf, goods.updateGoods);
    app.get('/showGoods/:id', OAuth2.checkAuth, goods.showGoods);
    app.post('/setGoodsStatus', OAuth2.checkAuth, goods.setGoodsStatus);
    app.get('/fetchGoods/:factionId', OAuth2.checkAuth, goods.fetchGoods);
    app.get('/tuhaolist/:payId/:factionId?', OAuth2.checkAuth, wxpay.listTuHao);
    app.post('/createOrder', OAuth2.checkAuth, wxpay.createOrder);
    app.get('/orderlist/:factionId/:status', OAuth2.checkAuth, wxpay.orderlist);
    app.post('/setOrderStatus', OAuth2.checkAuth, wxpay.setOrderStatus);
    app.get('/myOrder/:status', OAuth2.checkAuth, wxpay.myOrder);
    app.get('/showOrder/:id', OAuth2.checkAuth, wxpay.showOrder);
    app.post('/payCurrentOrder', OAuth2.checkAuth, wxpay.payCurrentOrder);
    app.post('/cancelOrder', OAuth2.checkAuth, wxpay.cancelOrder);

    /****支付****/
    app.get('/dashang/', OAuth2.checkAuth, wechat.dashang);
    //app.get('/wxpay/jsapi/test_payorder/:id', OAuth2.OAuth2WithoutPage, OAuth2.checkAuth, wxpay.payOrder);// 测试支付
    app.get('/wxpay/jsapi/payorder/:id/:code?', OAuth2.checkAuth, wxpay.payOrder);//OAuth2.OAuth2WithoutPage,
    app.post('/getWechatAddress', OAuth2.checkAuth, wxpay.getWechatAddress);
    app.post('/wxpay/jsapi/notify_url', wxpay.payNotify);
}

